package com.darco.darcoapp;

import eneter.messaging.endpoints.typedmessages.TypedResponseReceivedEventArgs;
import eneter.net.system.EventHandler;
import DARCOShared.responses.ResponseWrapper;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentActivity;

///Tutte le activity che vogliono usare il sistema di messaggistica devono derivare da questa classe!
public abstract class MessagingActivity extends FragmentActivity {
	private ProgressDialog progDailog;
	private Handler myEventHandler = new Handler(); //usato per reinstradare sul thread UI

	public EventHandler<TypedResponseReceivedEventArgs<ResponseWrapper>> myOnResponseHandler = new EventHandler<TypedResponseReceivedEventArgs<ResponseWrapper>>(){
		@Override
		public void onEvent(final Object sender, final TypedResponseReceivedEventArgs<ResponseWrapper> e)
		{
			myEventHandler.post(new Runnable()
			{
				@Override
				public void run()
				{
					onResponseReceived(sender, e);
				}
			});
		}
	};


	abstract void onResponseReceived(Object sender, TypedResponseReceivedEventArgs<ResponseWrapper> e);

	//funzioni in comune per le activity

	public boolean menuAbout(){
		AlertDialog dialogBox = new AlertDialog.Builder(this).create();
		dialogBox.setTitle("DARCO About");
		dialogBox.setMessage("This application is made by Elia Dal Santo and Riccardo Spolaor as project for the course " +
				"Wireless Networks teached by Prof. Caludio Enrico Palazzi");
		dialogBox.setButton("Ok",  new DialogInterface.OnClickListener(){

			@Override
			public void onClick(DialogInterface arg0, int arg1) {

			}
		});
		dialogBox.show();
		return true;


	}

	public boolean menuLogout(){
		Intent logout= new Intent(this,Login_Activity.class);
		logout.putExtra("MENU_LOGOUT", true);
		logout.putExtra("CLOSE_IMMEDIATELY", false);
		startActivity(logout);

		return true;
	}

	public void showLoadingDialog(String title, String message){
		hideLoadingDialog();
		progDailog = ProgressDialog.show(this, title, message, true);
		progDailog.setCancelable(true);
	}

	public void showLoadingDialog(String message){
		showLoadingDialog("Please wait...", message);
	}

	public void hideLoadingDialog(){
		if(progDailog != null && progDailog.isShowing())
			progDailog.dismiss();
	}

	public void onPopupCanceled(){
		
	}
}